﻿package com.bigstar.lolkor;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.StringTokenizer;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class BuilderChampion extends Activity implements OnClickListener, OnItemSelectedListener{
	
	public static int champ_id = -1;
	public static int level = 1;
	
	public static BuilderChampion instance;
	
	@Override 
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState); 
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
        instance = this;
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
		setContentView(R.layout.builder_champion);
        Spinner spinner = (Spinner) findViewById(R.id.level_spinner);
        spinner.setOnItemSelectedListener(this);
        ImageView iv = (ImageView)findViewById(R.id.champ_img);
        iv.setOnClickListener(this);
        Button b = (Button)findViewById(R.id.builder_save);
        b.setOnClickListener(this);
        b = (Button)findViewById(R.id.builder_search);
        b.setOnClickListener(this);
        b = (Button)findViewById(R.id.builder_delete);
        b.setOnClickListener(this);
	}
	
	@Override 
	public void onItemSelected(AdapterView<?> parent,View v,int position,long id){
		if((TextView)parent.getChildAt(0) != null){
			((TextView)parent.getChildAt(0)).setTextColor(Color.WHITE);
			((TextView)parent.getChildAt(0)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
			((TextView)parent.getChildAt(0)).setPadding(10, 0, 0, 0);	
		}
		level = position+1;
		set();
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch(v.getId()){
		case R.id.champ_img:
    		intent = new Intent(this, ChampionList.class);
    		intent.putExtra("builder", "on");
    		this.startActivity(intent);
    		break;
		case R.id.builder_save:
			tv = new EditText(BuilderChampion.this);
			new AlertDialog.Builder(BuilderChampion.this)
			.setTitle("저장할 파일명을 쓰세요.")
			.setView(tv)
			.setPositiveButton("저장", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
					save(tv.getText().toString());
				}
			})
			.setNegativeButton("취소", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int whichButton) {
				}
			})
			.create().show();
    		break;
		case R.id.builder_search:
			names = files();
			if(names != null){
				new AlertDialog.Builder(BuilderChampion.this)
				.setTitle("불러올 파일을 선택하세요.")
				.setPositiveButton("불러오기", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						load(loadString);
				        Spinner spinner = (Spinner) findViewById(R.id.level_spinner);
				        spinner.setSelection(level-1);
				        set();
					}
				})
				.setNegativeButton("닫기", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				})
				.setSingleChoiceItems(names, -1, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						loadString = names[whichButton];
					}
				})
				.create().show();
			}
    		break;
		case R.id.builder_delete:
			names = files();
			if(names != null){
				new AlertDialog.Builder(BuilderChampion.this)
				.setTitle("삭제할 파일을 선택하세요.")
				.setPositiveButton("삭제하기", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						delete(loadString);
						set();
					}
				})
				.setNegativeButton("닫기", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				})
				.setSingleChoiceItems(names, -1, new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						loadString = names[whichButton];
					}
				})
				.create().show();
			}
    		break;
		}
	}
	
	public void setStack(){
    	ImageView iv;
    	TextView tv;
    	if(champ_id != -1){
    		BigDecimal bd;
    		LinearLayout passive_layout = (LinearLayout)findViewById(R.id.builder_item_list_passive);
    		LinearLayout active_layout = (LinearLayout)findViewById(R.id.builder_item_list_active);
    		LinearLayout aurora_layout = (LinearLayout)findViewById(R.id.builder_item_list_aurora);
    		BuilderItem.getStat();
            //Spinner spinner = (Spinner) findViewById(R.id.level_spinner);
            //spinner.setSelection(level-1);
            iv = (ImageView)findViewById(R.id.champ_img);
			 String path = "champ_img/"+ChampionData.champions.get(champ_id).name_en+".jpg";
			 try {
				iv.setImageDrawable(Drawable.createFromStream(getAssets().open(path),"src"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            int health = (int) (ChampionData.champions.get(champ_id).health + ChampionData.champions.get(champ_id).health_per_level * level);
            float hrp1s = ((ChampionData.champions.get(champ_id).health_regen + ChampionData.champions.get(champ_id).health_regen_per_level * level) / 5);
            float hrp5s = (ChampionData.champions.get(champ_id).health_regen + ChampionData.champions.get(champ_id).health_regen_per_level * level);
            int mana = (int) (ChampionData.champions.get(champ_id).mana + ChampionData.champions.get(champ_id).mana_per_level * level);
            float mrp1s = ((ChampionData.champions.get(champ_id).mana_regen + ChampionData.champions.get(champ_id).mana_regen_per_level * level) / 5);
            float mrp5s = (ChampionData.champions.get(champ_id).mana_regen + ChampionData.champions.get(champ_id).mana_regen_per_level * level);
            float attack_speed = (ChampionData.champions.get(champ_id).attack_speed + ChampionData.champions.get(champ_id).attack_speed_per_level * (level-1));
            float damage = (ChampionData.champions.get(champ_id).damage + ChampionData.champions.get(champ_id).damage_per_level * level);
            float armor = (ChampionData.champions.get(champ_id).armor + ChampionData.champions.get(champ_id).armor_per_level * level);
            float mr = (ChampionData.champions.get(champ_id).mr + ChampionData.champions.get(champ_id).mr_per_level * level);
            float move_speed = (ChampionData.champions.get(champ_id).move_speed);
            
            tv = (TextView)findViewById(R.id.champ_name);
            tv.setText(ChampionData.champions.get(champ_id).name_kor);
            tv = (TextView)findViewById(R.id.rp_point);
            tv.setText(""+ChampionData.champions.get(champ_id).rp_point);
            tv = (TextView)findViewById(R.id.ip_point);
            tv.setText(""+ChampionData.champions.get(champ_id).ip_point);
            String stats = null;
            tv = (TextView)findViewById(R.id.builder_health_text);
            stats = health+"\r\n";
            stats = stats+String.format("%.1f", hrp1s)+"\r\n";
            stats = stats+String.format("%.1f", hrp5s)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_mana_text);
            stats = mana+"\r\n";
            stats = stats+String.format("%.1f", mrp1s)+"\r\n";
            stats = stats+String.format("%.1f", mrp5s)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_damage_text);
            stats = String.format("%.2f", attack_speed)+"\r\n";
            stats = stats+String.format("%.1f", damage)+"\r\n";
            stats = stats+"0\r\n0.0\r\n0%\r\n0.0\r\n0%\r\n0%\r\n200% ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_resistances_text);
            stats = String.format("%.1f", armor)+"\r\n";
            stats = stats+String.format("%.1f", mr)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_bonuses_text);
            stats = "0%\r\n0%\r\n0\r\n0.0% ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_general_text);
            if(ChampionData.champions.get(champ_id).name_en.equals("Tristana")){
                stats = (int)((ChampionData.champions.get(champ_id).range)+ 9 * (level-1))+"\r\n";	
            }else{
                stats = (int)(ChampionData.champions.get(champ_id).range)+"\r\n";	
            }
            stats = stats + (int)move_speed+"\r\n0 ";
            tv.setText(stats);
            
            int bonus_health = (int) ((Rune.getStat("health_per_lvl")*level) + Rune.getStat("health"));
         	bonus_health += ((float)(health * (Rune.getStat("health_per")/100)));
            bonus_health += (float) (level*(1.5*Builder.masteries[1][4]));
            bonus_health += 30*Builder.masteries[1][7];
            if(Builder.masteries[1][15] == 1){
            	bonus_health += ((float)(health * 0.03));
            }
            bonus_health += BuilderItem.item_total_stat.health;
            bonus_health += BuilderItem.item_stack_stat.health;
            bonus_health += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "health", false);
            float bonus_hrp5s = Rune.getStat("health_regen") + (Rune.getStat("health_regen_per_lvl") * level);
            bonus_hrp5s += 1*Builder.masteries[1][5];
            bonus_hrp5s += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "health_regen", false);
            bonus_hrp5s += BuilderItem.item_total_stat.health_regen;
            bonus_hrp5s += BuilderItem.item_stack_stat.health_regen;
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Force of Nature")){
			            bonus_hrp5s += ((float)health*0.0175);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "매초당 0.35%의 체력을 회복합니다.", false);
						break;
					}
				}
			}
			
            int total_health = (int) (health + bonus_health);
            float total_hrp5s = hrp5s + bonus_hrp5s;
            
            int bonus_mana = (int) ((Rune.getStat("mana_per_lvl")*level) + Rune.getStat("mana"));
            bonus_mana += (float) (level*(4*Builder.masteries[2][2]));
            bonus_mana += BuilderItem.item_total_stat.mana;
            bonus_mana += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mana", false);
            bonus_mana += BuilderItem.item_stack_stat.mana;
            float bonus_mrp5s = Rune.getStat("mana_regen") + (Rune.getStat("mana_regen_per_lvl") * level);
            bonus_mrp5s += Builder.masteries[2][5]*1;
            bonus_mrp5s += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mana_regen", false);
            bonus_mrp5s += BuilderItem.item_total_stat.mana_regen;
            int total_mana = (int) (mana + bonus_mana);
            float total_mrp5s = mrp5s + bonus_mrp5s;
           
            float bonus_attack_speed = ChampionData.champions.get(champ_id).attack_speed*(Rune.getStat("attack_speed")/100);
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*Builder.masteries[0][4]));
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*BuilderItem.item_total_stat.attack_speed));
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*BuilderItem.item_stack_stat.attack_speed));
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "attack_speed", false)));
            float bonus_damage = Rune.getStat("damage") + (Rune.getStat("damage_per_lvl") * level);
            bonus_damage += Builder.masteries[0][1]*1;
            bonus_damage += (float) (level*(0.125*Builder.masteries[0][7]));
            bonus_damage += BuilderItem.item_total_stat.damage;
            bonus_damage += BuilderItem.item_stack_stat.damage;
            bonus_damage += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "damage", false);
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Atma's Impaler")){
						bonus_damage += ((float)total_health * 0.015);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "전체 체력의 1.5%만큼 공격력이 상승합니다.", false);
						break;
					}
				}
			}
            float bonus_ap = Rune.getStat("ap") + (Rune.getStat("ap_per_lvl") * level);
            bonus_ap += Builder.masteries[0][2]*1;
            bonus_ap += (float) (level*(0.25*Builder.masteries[0][13]));
            bonus_ap += (float) (bonus_ap*(0.0125*Builder.masteries[0][15]));
            bonus_ap += BuilderItem.item_total_stat.ap;
            bonus_ap += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "ap", false);
            bonus_ap += BuilderItem.item_stack_stat.ap;
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Archangel's Staff")){
						bonus_ap += ((float)mana*0.03);
					}
				}
			}
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("The Hex Core") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Power") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Graviton") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Death")){
						bonus_ap += 3*level;
						break;
					}
				}
			}
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Rabadon's Deathcap")){
						bonus_ap += ((float)bonus_ap*0.3);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "주문력이 30%만큼 상승합니다.", false);
						break;
					}
				}
			}
			float bonus_armor_pen = Rune.getStat("armor_pen");
			bonus_armor_pen += Rune.getStat("two_pen_0") * 1; //FIXME 물관마관 수정
			bonus_armor_pen += Rune.getStat("two_pen_1") * 2;
            bonus_armor_pen += Builder.masteries[0][14]*2;
            bonus_armor_pen += BuilderItem.item_total_stat.armor_pen;
            bonus_armor_pen += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor_pen", false);
            float bonus_armor_pen_per = 0;
            bonus_armor_pen_per += Builder.masteries[0][8]*10;
            bonus_armor_pen_per += BuilderItem.item_total_stat.armor_pen_per;
            bonus_armor_pen_per += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor_pen_per", false);
            float bonus_magic_pen = 0;
            bonus_magic_pen += BuilderItem.item_total_stat.magic_pen;
            bonus_magic_pen += Rune.getStat("magic_pen");
			bonus_magic_pen += Rune.getStat("two_pen_0") * 0.57;
            bonus_magic_pen += Rune.getStat("two_pen_1") * 1.3;
            bonus_magic_pen += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "magic_pen", false);
            float bonus_magic_pen_per = 0;
            bonus_magic_pen_per += Builder.masteries[0][9]*10;
            bonus_magic_pen_per += BuilderItem.item_total_stat.magic_pen_per;
            bonus_magic_pen_per += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "magic_pen_per", false);
            float bonus_cri_chance = Rune.getStat("cri_chance");
            bonus_cri_chance += BuilderItem.item_total_stat.cri_chance;
            
            float bonus_cri_damage = Rune.getStat("cri_damage");
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Infinity Edge")){
						bonus_cri_damage += 50;
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "치명타가 200%의 피해 대신 250%의 피해를 입힙니다.", false);
						break;
					}
				}
			}
            bonus_cri_damage += Builder.masteries[0][11]*10;
            float total_attack_speed = attack_speed+bonus_attack_speed;
            float total_damage = damage+bonus_damage;
            float total_ap = 0+bonus_ap;
            float total_armor_pen = 0+bonus_armor_pen;
            float total_magic_pen = 0+bonus_magic_pen;
            float total_armor_pen_per = 0+bonus_armor_pen_per;
            float total_magic_pen_per = 0+bonus_magic_pen_per;
            float total_cri_chance = 0+bonus_cri_chance;
            float total_cri_damage = 200+bonus_cri_damage;
            
            float bonus_armor = Rune.getStat("armor") + (Rune.getStat("armor_per_lvl") * level);
            bonus_armor += Builder.masteries[1][2] * 2;
            bonus_armor += BuilderItem.item_total_stat.armor;
            bonus_armor += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor", false);
            float bonus_mr = Rune.getStat("mr") + (Rune.getStat("mr_per_lvl") * level);
            bonus_mr += Builder.masteries[1][1] * 2;
            bonus_mr += BuilderItem.item_total_stat.mr;
            bonus_mr += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mr", false);
            float total_armor = armor+bonus_armor;
            float total_mr = mr+bonus_mr;
            
            float bonus_life_steal = 0;
            bonus_life_steal += Rune.getStat("life_steal");
            bonus_life_steal += Builder.masteries[0][12]*1;
            bonus_life_steal += BuilderItem.item_total_stat.life_steal;
            bonus_life_steal += BuilderItem.item_stack_stat.life_steal;
            bonus_life_steal += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "life_steal", false);
            float bonus_spell_vamp = 0;
            bonus_spell_vamp += Rune.getStat("spell_vamp");
            bonus_spell_vamp += Builder.masteries[2][8]*1;
            bonus_spell_vamp += BuilderItem.item_total_stat.spell_vamp;
            bonus_spell_vamp += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "spell_vamp", false);
            float bonus_tenacity = 0;
            bonus_tenacity += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "tenacity", false);
            float bonus_cooldowns = Rune.getStat("cooldowns") + (Rune.getStat("cooldowns_per_lvl") * level);
            bonus_cooldowns += Builder.masteries[0][5]*1;
            bonus_cooldowns += (float) (level*(0.15*Builder.masteries[1][12]));
            bonus_cooldowns += Builder.masteries[2][14]*2;
            bonus_cooldowns += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "cooldown_reduction", false);
            bonus_cooldowns += BuilderItem.item_total_stat.cooldown_reduction;
            bonus_cooldowns += BuilderItem.item_stack_stat.cooldown_reduction;
            if(bonus_cooldowns >= 45.0f){
            	bonus_cooldowns = 45.0f;
            }
            float total_life_steal = 0+bonus_life_steal;
            float total_spell_vamp = 0+bonus_spell_vamp;
            float total_tenacity = 0+bonus_tenacity;
            float total_cooldowns = 0+bonus_cooldowns;
            
            float bonus_range = 0;
            float move_per = 0;
            float bonus_move_speed =  BuilderItem.item_total_stat.move_speed;
            move_per = ((float)BuilderItem.item_total_stat.move_speed_per/100);
            move_per += (Rune.getStat("move_speed")/100);
            move_per += (0.005*Builder.masteries[2][4]);
            move_per += (0.01*Builder.masteries[1][11]);
            move_per += ((float)BuilderItem.item_stack_stat.move_speed_per/100);
            bonus_move_speed += (move_speed+bonus_move_speed)*move_per;
            bonus_move_speed += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "move_speed", false);
            float penalty = 0;
            if(move_speed+bonus_move_speed > 415.00f){
            	penalty = (move_speed+bonus_move_speed - 415.00f)*0.20f;
            }else if(move_speed+bonus_move_speed > 490.00f){
              	penalty = (move_speed+bonus_move_speed - 490.00f)*0.50f;
            }
    		bd = new BigDecimal(bonus_move_speed-penalty);
            float bonus_gold = Rune.getStat("hsec_gold");
            bonus_gold += (float) (0.5*Builder.masteries[2][7]);
            bonus_gold += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "gold_regen", false);
            int total_range = (int) ((ChampionData.champions.get(champ_id).range)+bonus_range);
            if(ChampionData.champions.get(champ_id).name_en.equals("Tristana")){
            	total_range = total_range + 9 * (level-1);
            }
            int total_move_speed = (int) (move_speed+bd.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
            float total_gold = 0+bonus_gold;  
            
        	float temp_ap = 0;
        	int tempHealth = 0;
        	
            if(ChampionData.champions.get(champ_id).name_en.equals("Vladimir")){
            	tempHealth = (int) (bonus_ap*1.4);
            	temp_ap = bonus_health/40;
            }
            
            bonus_health += tempHealth;
            total_health += tempHealth;
            bonus_ap += temp_ap;
            total_ap += temp_ap;
            
            if(ChampionData.champions.get(champ_id).name_en.equals("Galio")){
            	total_ap += total_mr / 2;
            }
            /*
             * 10/12.5/17.5/20/22.5/25%
             */
            if(ChampionData.champions.get(champ_id).name_en.equals("Hecarim")){
            	if(level < 4){
                	total_damage += bonus_move_speed * 0.1;
            	}else if(level < 7){
                	total_damage += bonus_move_speed * 0.125;
            	}else if(level < 10){
                	total_damage += bonus_move_speed * 0.175;
            	}else if(level < 13){
                	total_damage += bonus_move_speed * 0.20;
            	}else if(level < 16){
                	total_damage += bonus_move_speed * 0.225;
            	}else{
                	total_damage += bonus_move_speed * 0.25;	
            	}
            }
            
            if(ChampionData.champions.get(champ_id).name_en.equals("Rammus")){
            	total_damage += total_armor * 0.25;	
            }
            
            tv = (TextView)findViewById(R.id.builder_health_text_with_bonus);
            stats = total_health+"(+"+bonus_health+")"+"\r\n";
            stats = stats+String.format("%.1f", (total_hrp5s/5))+"(+"+String.format("%.1f", (bonus_hrp5s/5))+")"+"\r\n";
            stats = stats+String.format("%.1f", total_hrp5s)+"(+"+String.format("%.1f", bonus_hrp5s)+") ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_mana_text_with_bonus);
            stats = total_mana+"(+"+bonus_mana+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mrp5s/5)+"(+"+String.format("%.1f", bonus_mrp5s/5)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mrp5s)+"(+"+String.format("%.1f", bonus_mrp5s)+") ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_damage_text_with_bonus);
            stats = String.format("%.2f", total_attack_speed)+"(+"+String.format("%.2f", bonus_attack_speed)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_damage)+"(+"+String.format("%.1f", bonus_damage)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_ap)+"(+"+String.format("%.1f", bonus_ap)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_armor_pen)+"(+"+String.format("%.1f", bonus_armor_pen)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_armor_pen_per)+"%"+"(+"+String.format("%.1f", bonus_armor_pen_per)+"%)"+"\r\n";
            stats = stats+String.format("%.1f", total_magic_pen)+"(+"+String.format("%.1f", total_magic_pen)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_magic_pen_per)+"%"+"(+"+String.format("%.1f", bonus_magic_pen_per)+"%)"+"\r\n";
            stats = stats+String.format("%.1f", total_cri_chance)+"%(+"+String.format("%.1f", bonus_cri_chance)+"%)"+"\r\n";
            stats = stats+(int)total_cri_damage+"%(+"+(int)bonus_cri_damage+"%)"+" "; 
            tv.setText(stats);
            stats = null;            
            tv = (TextView)findViewById(R.id.builder_resistances_text_with_bonus);
            stats = String.format("%.1f", total_armor)+"(+"+String.format("%.1f", bonus_armor)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mr)+"(+"+String.format("%.1f", bonus_mr)+")"+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_bonuses_text_with_bonus);
            stats = total_life_steal+"%(+"+bonus_life_steal+"%)"+"\r\n";
            stats = stats+total_spell_vamp+"%(+"+bonus_spell_vamp+"%)"+"\r\n";
            stats = stats+total_tenacity+"(+"+bonus_tenacity+")"+"\r\n";
            stats = stats+String.format("%.1f", total_cooldowns)+"%(+"+String.format("%.1f", bonus_cooldowns)+"%)"+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_general_text_with_bonus);
            stats = total_range+"(+"+bonus_range+")"+"\r\n";
            stats = stats+total_move_speed+"(+"+bd.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()+")"+"\r\n";
            stats = stats+String.format("%.2f", total_gold)+"(+"+String.format("%.2f", bonus_gold)+")"+" ";
            tv.setText(stats);
            stats = null;
    	}
	}
	
	public void set(){
		BuilderItem.item_stack_stat = new ItemTemplate();
    	ImageView iv;
    	TextView tv;
    	if(champ_id != -1){
    		BigDecimal bd;
    		LinearLayout passive_layout = (LinearLayout)findViewById(R.id.builder_item_list_passive);
    		passive_layout.removeAllViews();
    		LinearLayout active_layout = (LinearLayout)findViewById(R.id.builder_item_list_active);
    		active_layout.removeAllViews();
    		LinearLayout aurora_layout = (LinearLayout)findViewById(R.id.builder_item_list_aurora);
    		aurora_layout.removeAllViews();
    		BuilderItem.getStat();
            //Spinner spinner = (Spinner) findViewById(R.id.level_spinner);
            //spinner.setSelection(level-1);
            iv = (ImageView)findViewById(R.id.champ_img);
			 String path = "champ_img/"+ChampionData.champions.get(champ_id).name_en+".jpg";
			 try {
				iv.setImageDrawable(Drawable.createFromStream(getAssets().open(path),"src"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            int health = (int) (ChampionData.champions.get(champ_id).health + ChampionData.champions.get(champ_id).health_per_level * level);
            float hrp1s = ((ChampionData.champions.get(champ_id).health_regen + ChampionData.champions.get(champ_id).health_regen_per_level * level) / 5);
            float hrp5s = (ChampionData.champions.get(champ_id).health_regen + ChampionData.champions.get(champ_id).health_regen_per_level * level);
            int mana = (int) (ChampionData.champions.get(champ_id).mana + ChampionData.champions.get(champ_id).mana_per_level * level);
            float mrp1s = ((ChampionData.champions.get(champ_id).mana_regen + ChampionData.champions.get(champ_id).mana_regen_per_level * level) / 5);
            float mrp5s = (ChampionData.champions.get(champ_id).mana_regen + ChampionData.champions.get(champ_id).mana_regen_per_level * level);
            float attack_speed = (ChampionData.champions.get(champ_id).attack_speed + ChampionData.champions.get(champ_id).attack_speed_per_level * (level-1));
            float damage = (ChampionData.champions.get(champ_id).damage + ChampionData.champions.get(champ_id).damage_per_level * level);
            float armor = (ChampionData.champions.get(champ_id).armor + ChampionData.champions.get(champ_id).armor_per_level * level);
            float mr = (ChampionData.champions.get(champ_id).mr + ChampionData.champions.get(champ_id).mr_per_level * level);
            float move_speed = (ChampionData.champions.get(champ_id).move_speed);
            tv = (TextView)findViewById(R.id.champ_name);
            tv.setText(ChampionData.champions.get(champ_id).name_kor);
            tv = (TextView)findViewById(R.id.rp_point);
            tv.setText(""+ChampionData.champions.get(champ_id).rp_point);
            tv = (TextView)findViewById(R.id.ip_point);
            tv.setText(""+ChampionData.champions.get(champ_id).ip_point);
            String stats = null;
            tv = (TextView)findViewById(R.id.builder_health_text);
            stats = health+"\r\n";
            stats = stats+String.format("%.1f", hrp1s)+"\r\n";
            stats = stats+String.format("%.1f", hrp5s)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_mana_text);
            stats = mana+"\r\n";
            stats = stats+String.format("%.1f", mrp1s)+"\r\n";
            stats = stats+String.format("%.1f", mrp5s)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_damage_text);
            stats = String.format("%.2f", attack_speed)+"\r\n";
            stats = stats+String.format("%.1f", damage)+"\r\n";
            stats = stats+"0\r\n0.0\r\n0%\r\n0.0\r\n0%\r\n0%\r\n200% ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_resistances_text);
            stats = String.format("%.1f", armor)+"\r\n";
            stats = stats+String.format("%.1f", mr)+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_bonuses_text);
            stats = "0%\r\n0%\r\n0\r\n0.0% ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_general_text);
            if(ChampionData.champions.get(champ_id).name_en.equals("Tristana")){
                stats = (int)((ChampionData.champions.get(champ_id).range)+ 9 * (level-1))+"\r\n";	
            }else{
                stats = (int)(ChampionData.champions.get(champ_id).range)+"\r\n";	
            }
            stats = stats + (int)move_speed+"\r\n0 ";
            tv.setText(stats);
            
            int bonus_health = (int) ((Rune.getStat("health_per_lvl")*level) + Rune.getStat("health"));
            bonus_health += BuilderItem.item_total_stat.health;
            bonus_health += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "health", true);
            bonus_health += (float) (level*(1.5*Builder.masteries[1][4]));
            bonus_health += 30*Builder.masteries[1][7];
         	bonus_health += ((float)((health+bonus_health) * (Rune.getStat("health_per")/100)));
            if(Builder.masteries[1][15] == 1){
            	bonus_health += ((float)((health+bonus_health) * 0.03));
            }
            float bonus_hrp5s = Rune.getStat("health_regen") + (Rune.getStat("health_regen_per_lvl") * level);
            bonus_hrp5s += 1*Builder.masteries[1][5];
            bonus_hrp5s += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "health_regen", true);
            bonus_hrp5s += BuilderItem.item_total_stat.health_regen;
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Force of Nature")){
			            bonus_hrp5s += ((float)health*0.0175);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "매초당 0.35%의 체력을 회복합니다.", true);
						break;
					}
				}
			}
            
            int total_health = (int) (health + bonus_health);
            float total_hrp5s = hrp5s + bonus_hrp5s;
            
            int bonus_mana = (int) ((Rune.getStat("mana_per_lvl")*level) + Rune.getStat("mana"));
            bonus_mana += (float) (level*(4*Builder.masteries[2][2]));
            bonus_mana += BuilderItem.item_total_stat.mana;
            bonus_mana += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mana", true);
            float bonus_mrp5s = Rune.getStat("mana_regen") + (Rune.getStat("mana_regen_per_lvl") * level);
            bonus_mrp5s += Builder.masteries[2][5]*1;
            bonus_mrp5s += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mana_regen", true);
            bonus_mrp5s += BuilderItem.item_total_stat.mana_regen;
            int total_mana = (int) (mana + bonus_mana);
            float total_mrp5s = mrp5s + bonus_mrp5s;
            
            float bonus_attack_speed = ChampionData.champions.get(champ_id).attack_speed*(Rune.getStat("attack_speed")/100);
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*Builder.masteries[0][4]));
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*BuilderItem.item_total_stat.attack_speed));
            bonus_attack_speed += (float) (ChampionData.champions.get(champ_id).attack_speed*(0.01*BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "attack_speed", true)));
            float bonus_damage = Rune.getStat("damage") + (Rune.getStat("damage_per_lvl") * level);
            bonus_damage += Builder.masteries[0][1]*1;
            bonus_damage += (float) (level*(0.125*Builder.masteries[0][7]));
            bonus_damage += BuilderItem.item_total_stat.damage;
            bonus_damage += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "damage", true);
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Atma's Impaler")){
						bonus_damage += ((float)total_health * 0.015);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "전체 체력의 1.5%만큼 공격력이 상승합니다.", true);
						break;
					}
				}
			}
            float bonus_ap = Rune.getStat("ap") + (Rune.getStat("ap_per_lvl") * level);
            bonus_ap += Builder.masteries[0][2]*1;
            bonus_ap += (float) (level*(0.25*Builder.masteries[0][13]));
            bonus_ap += (float) (bonus_ap*(0.0125*Builder.masteries[0][15]));
            bonus_ap += BuilderItem.item_total_stat.ap;
            bonus_ap += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "ap", true);
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Archangel's Staff")){
						bonus_ap += ((float)mana*0.03);
					}
				}
			}
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("The Hex Core") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Power") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Graviton") ||
							ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Augment: Death")){
						bonus_ap += 3*level;
						break;
					}
				}
			}
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Rabadon's Deathcap")){
						bonus_ap += ((float)bonus_ap*0.3);
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "주문력이 30%만큼 상승합니다.", true);
						break;
					}
				}
			}
			float bonus_armor_pen = Rune.getStat("armor_pen");
			bonus_armor_pen += Rune.getStat("two_pen_0") * 1; //FIXME 물관마관 수정
			bonus_armor_pen += Rune.getStat("two_pen_1") * 2;
            bonus_armor_pen += Builder.masteries[0][14]*2;
            bonus_armor_pen += BuilderItem.item_total_stat.armor_pen;
            bonus_armor_pen += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor_pen", true);
            float bonus_armor_pen_per = 0;
            bonus_armor_pen_per += Builder.masteries[0][8]*10;
            bonus_armor_pen_per += BuilderItem.item_total_stat.armor_pen_per;
            bonus_armor_pen_per += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor_pen_per", true);
            float bonus_magic_pen = 0;
            bonus_magic_pen += BuilderItem.item_total_stat.magic_pen;
            bonus_magic_pen += Rune.getStat("magic_pen");
			bonus_magic_pen += Rune.getStat("two_pen_0") * 0.57;
            bonus_magic_pen += Rune.getStat("two_pen_1") * 1.3;
            bonus_magic_pen += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "magic_pen", true);
            float bonus_magic_pen_per = 0;
            bonus_magic_pen_per += Builder.masteries[0][9]*10;
            bonus_magic_pen_per += BuilderItem.item_total_stat.magic_pen_per;
            bonus_magic_pen_per += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "magic_pen_per", true);
            float bonus_cri_chance = Rune.getStat("cri_chance");
            bonus_cri_chance += BuilderItem.item_total_stat.cri_chance;
            
            float bonus_cri_damage = Rune.getStat("cri_damage");
			for(int i = 0; i < BuilderItem.item_id.length; i++){
				if(BuilderItem.item_id[i] != -1){
					if(ItemData.items.get(BuilderItem.item_id[i]).name_en.equals("Infinity Edge")){
						bonus_cri_damage += 50;
						BuilderItem.addUniqueItem(this, passive_layout, BuilderItem.item_id[i], "치명타가 200%의 피해 대신 250%의 피해를 입힙니다.", true);
						break;
					}
				}
			}
            bonus_cri_damage += Builder.masteries[0][11]*10;
            float total_attack_speed = attack_speed+bonus_attack_speed;
            float total_damage = damage+bonus_damage;
            float total_ap = 0+bonus_ap;
            float total_armor_pen = 0+bonus_armor_pen;
            float total_magic_pen = 0+bonus_magic_pen;
            float total_armor_pen_per = 0+bonus_armor_pen_per;
            float total_magic_pen_per = 0+bonus_magic_pen_per;
            float total_cri_chance = 0+bonus_cri_chance;
            float total_cri_damage = 200+bonus_cri_damage;
            
            float bonus_armor = Rune.getStat("armor") + (Rune.getStat("armor_per_lvl") * level);
            bonus_armor += Builder.masteries[1][2] * 2;
            bonus_armor += BuilderItem.item_total_stat.armor;
            bonus_armor += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "armor", true);
            float bonus_mr = Rune.getStat("mr") + (Rune.getStat("mr_per_lvl") * level);
            bonus_mr += Builder.masteries[1][1] * 2;
            bonus_mr += BuilderItem.item_total_stat.mr;
            bonus_mr += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "mr", true);
            float total_armor = armor+bonus_armor;
            float total_mr = mr+bonus_mr;
            
            float bonus_life_steal = 0;
            bonus_life_steal += Rune.getStat("life_steal");
            bonus_life_steal += Builder.masteries[0][12]*1;
            bonus_life_steal += BuilderItem.item_total_stat.life_steal;
            bonus_life_steal += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "life_steal", true);
            float bonus_spell_vamp = 0;
            bonus_spell_vamp += Rune.getStat("spell_vamp");
            bonus_spell_vamp += Builder.masteries[2][8]*1;
            bonus_spell_vamp += BuilderItem.item_total_stat.spell_vamp;
            bonus_spell_vamp += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "spell_vamp", true);
            float bonus_tenacity = 0;
            bonus_tenacity += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "tenacity", true);
            float bonus_cooldowns = Rune.getStat("cooldowns") + (Rune.getStat("cooldowns_per_lvl") * level);
            bonus_cooldowns += Builder.masteries[0][5]*1;
            bonus_cooldowns += (float) (level*(0.15*Builder.masteries[1][12]));
            bonus_cooldowns += Builder.masteries[2][14]*2;
            bonus_cooldowns += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "cooldown_reduction", true);
            bonus_cooldowns += BuilderItem.item_total_stat.cooldown_reduction;
            if(bonus_cooldowns >= 40.0f){
            	bonus_cooldowns = 40.0f;
            }
            float total_life_steal = 0+bonus_life_steal;
            float total_spell_vamp = 0+bonus_spell_vamp;
            float total_tenacity = 0+bonus_tenacity;
            float total_cooldowns = 0+bonus_cooldowns;
            
            float bonus_range = 0;
            float move_per = 0;
            float bonus_move_speed =  BuilderItem.item_total_stat.move_speed;
            move_per = ((float)BuilderItem.item_total_stat.move_speed_per/100);
            move_per += (Rune.getStat("move_speed")/100);
            move_per += (0.005*Builder.masteries[2][4]);
            move_per += (0.01*Builder.masteries[1][11]);
            bonus_move_speed += (move_speed+bonus_move_speed)*move_per;
            bonus_move_speed += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "move_speed", true);
            float penalty = 0;
            if(move_speed+bonus_move_speed > 415.00f){
            	penalty = (move_speed+bonus_move_speed - 415.00f)*0.20f;
            }else if(move_speed+bonus_move_speed > 490.00f){
              	penalty = (move_speed+bonus_move_speed - 490.00f)*0.50f;
            }
    		bd = new BigDecimal(bonus_move_speed-penalty);
            float bonus_gold = Rune.getStat("hsec_gold");
            bonus_gold += (float) (0.5*Builder.masteries[2][7]);
            bonus_gold += BuilderItem.TwoOptionItem(passive_layout, active_layout, aurora_layout, this, "gold_regen", true);
            int total_range = (int) ((ChampionData.champions.get(champ_id).range)+bonus_range);
            if(ChampionData.champions.get(champ_id).name_en.equals("Tristana")){
            	total_range = total_range + 9 * (level-1);
            }
            int total_move_speed = (int) (move_speed+bd.setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
            float total_gold = 0+bonus_gold;
            
        	float temp_ap = 0;
        	int tempHealth = 0;
        	
            if(ChampionData.champions.get(champ_id).name_en.equals("Vladimir")){
            	tempHealth = (int) (bonus_ap*1.4);
            	temp_ap = bonus_health/40;
            }
            
            bonus_health += tempHealth;
            total_health += tempHealth;
            bonus_ap += temp_ap;
            total_ap += temp_ap;
            
            if(ChampionData.champions.get(champ_id).name_en.equals("Galio")){
            	total_ap += total_mr / 2;
            }
            
            if(ChampionData.champions.get(champ_id).name_en.equals("Hecarim")){
            	if(level < 4){
                	total_damage += bonus_move_speed * 0.1;
            	}else if(level < 7){
                	total_damage += bonus_move_speed * 0.125;
            	}else if(level < 10){
                	total_damage += bonus_move_speed * 0.175;
            	}else if(level < 13){
                	total_damage += bonus_move_speed * 0.20;
            	}else if(level < 16){
                	total_damage += bonus_move_speed * 0.225;
            	}else{
                	total_damage += bonus_move_speed * 0.25;
            	}
            }
            
            if(ChampionData.champions.get(champ_id).name_en.equals("Rammus")){
            	total_damage += total_armor * 0.25;	
            }
            
            tv = (TextView)findViewById(R.id.builder_health_text_with_bonus);
            stats = total_health+"(+"+bonus_health+")"+"\r\n";
            stats = stats+String.format("%.1f", (total_hrp5s/5))+"(+"+String.format("%.1f", (bonus_hrp5s/5))+")"+"\r\n";
            stats = stats+String.format("%.1f", total_hrp5s)+"(+"+String.format("%.1f", bonus_hrp5s)+") ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_mana_text_with_bonus);
            stats = total_mana+"(+"+bonus_mana+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mrp5s/5)+"(+"+String.format("%.1f", bonus_mrp5s/5)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mrp5s)+"(+"+String.format("%.1f", bonus_mrp5s)+") ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_damage_text_with_bonus);
            stats = String.format("%.2f", total_attack_speed)+"(+"+String.format("%.2f", bonus_attack_speed)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_damage)+"(+"+String.format("%.1f", bonus_damage)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_ap)+"(+"+String.format("%.1f", bonus_ap)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_armor_pen)+"(+"+String.format("%.1f", bonus_armor_pen)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_armor_pen_per)+"%"+"(+"+String.format("%.1f", bonus_armor_pen_per)+"%)"+"\r\n";
            stats = stats+String.format("%.1f", total_magic_pen)+"(+"+String.format("%.1f", total_magic_pen)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_magic_pen_per)+"%"+"(+"+String.format("%.1f", bonus_magic_pen_per)+"%)"+"\r\n";
            stats = stats+String.format("%.1f", total_cri_chance)+"%(+"+String.format("%.1f", bonus_cri_chance)+"%)"+"\r\n";
            stats = stats+(int)total_cri_damage+"%(+"+(int)bonus_cri_damage+"%)"+" "; 
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_resistances_text_with_bonus);
            stats = String.format("%.1f", total_armor)+"(+"+String.format("%.1f", bonus_armor)+")"+"\r\n";
            stats = stats+String.format("%.1f", total_mr)+"(+"+String.format("%.1f", bonus_mr)+")"+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_bonuses_text_with_bonus);
            stats = total_life_steal+"%(+"+bonus_life_steal+"%)"+"\r\n";
            stats = stats+total_spell_vamp+"%(+"+bonus_spell_vamp+"%)"+"\r\n";
            stats = stats+total_tenacity+"(+"+bonus_tenacity+")"+"\r\n";
            stats = stats+String.format("%.1f", total_cooldowns)+"%(+"+String.format("%.1f", bonus_cooldowns)+"%)"+" ";
            tv.setText(stats);
            stats = null;
            tv = (TextView)findViewById(R.id.builder_general_text_with_bonus);
            stats = total_range+"(+"+bonus_range+")"+"\r\n";
            stats = stats+total_move_speed+"(+"+bd.setScale(0, BigDecimal.ROUND_HALF_UP).intValue()+")"+"\r\n";
            stats = stats+String.format("%.2f", total_gold)+"(+"+String.format("%.2f", bonus_gold)+")"+" ";
            tv.setText(stats);
            stats = null;
			setStack();
    	}
	}
	
    @Override
    protected void onResume() {
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
    	super.onResume();
        set();
    }

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub
		
	}
	EditText tv;
	String loadString;
	String[] names;
	
	public String[] files(){
		File files = new File("/sdcard/Android/data/LOLDATA/builder");
		String str = Environment.getExternalStorageState();
		String[] names = null;
		if ( str.equals(Environment.MEDIA_MOUNTED)) {
			if(!files.exists()){
				files.mkdirs();	
			}
			if(files.listFiles().length > 0)
			{
				names = new String[files.listFiles().length];
				int i = 0;
				for(File file : files.listFiles()){
					names[i] = file.getName();
					i++;
				}
			}	
		}
		return names;
	}

	public void delete(String name){
		String str = Environment.getExternalStorageState();
		if ( str.equals(Environment.MEDIA_MOUNTED)) {
			String dirPath = "/sdcard/Android/data/LOLDATA/builder";
			File dir = new File(dirPath);
			if(!dir.exists()){
				dir.mkdirs();	
			}
			File file = new File(dirPath + "/"+name);
			if(file.exists()){
				file.delete();
				Toast.makeText(this, "delete success", Toast.LENGTH_SHORT).show();
			}
		}
	}
	
	public void load(String name){
		String str = Environment.getExternalStorageState();
		if ( str.equals(Environment.MEDIA_MOUNTED)) {
			String dirPath = "/sdcard/Android/data/LOLDATA/builder";
			File dir = new File(dirPath);
			if(!dir.exists()){
				dir.mkdirs();	
			}
			File file = new File(dirPath + "/"+name);
			if(file.exists()){
				String line = null;
				DataInputStream dis = null;
				StringTokenizer st = null;
				FileInputStream in = null;
				try {
					in = new FileInputStream(file);
					dis = new DataInputStream(in);
					line = dis.readLine();
					st = new StringTokenizer(line, ";");
					String champName = st.nextToken();
					for(int i = 0; i < ChampionData.champions.size(); i ++){
						if(ChampionData.champions.get(i).name_en.equals(champName)){
							champ_id = i;
						}
					}
					level = Integer.parseInt(st.nextToken());
					line = dis.readLine();
					st = new StringTokenizer(line, ";");
					for(int i = 0; i < 6; i++){
						BuilderItem.item_id[i] = Integer.parseInt(st.nextToken());
					}
					for(int i = 0; i < 6; i++){
						BuilderItem.item_gold[i] = Integer.parseInt(st.nextToken());
					}
					line = dis.readLine();
					st = new StringTokenizer(line, ";");
					for(int i = 0; i < 9; i++){
						Rune.red[i] = Integer.parseInt(st.nextToken());
					}
					for(int i = 0; i < 9; i++){
						Rune.blue[i] = Integer.parseInt(st.nextToken());
					}
					for(int i = 0; i < 9; i++){
						Rune.yellow[i] = Integer.parseInt(st.nextToken());
					}
					Rune.big[0] = Integer.parseInt(st.nextToken());
					Rune.big[1] = Integer.parseInt(st.nextToken());
					Rune.big[2] = Integer.parseInt(st.nextToken());
					line = dis.readLine();
					st = new StringTokenizer(line, ";");
					for(int j = 0; j < 17; j++){
						Builder.masteries[0][j] = Integer.parseInt(st.nextToken()); 
					}
					for(int j = 0; j < 16; j++){
						Builder.masteries[1][j] = Integer.parseInt(st.nextToken()); 
					}
					for(int j = 0; j < 16; j++){
						Builder.masteries[2][j] = Integer.parseInt(st.nextToken()); 
					}
					Toast.makeText(this, "load success", Toast.LENGTH_SHORT).show();
				} catch (IOException e) {
				}finally{
					try {
						dis.close();
						in.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}
	}

	public void save(String name){
		String str = Environment.getExternalStorageState();
		if ( str.equals(Environment.MEDIA_MOUNTED)) {
			String dirPath = "/sdcard/Android/data/LOLDATA/builder";
			File dir = new File(dirPath);
			if(!dir.exists()){
				dir.mkdirs();	
			}
			File file = new File(dirPath + "/"+name+".txt");
			if(file.exists()){
				file.delete();
				file = new File(dirPath + "/"+name+".txt"); //FIXME 빌더 세이브 수정
			}
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream(file);
				str = ChampionData.champions.get(champ_id).name_en+";"+level+"\r\n";
				for(int i = 0; i < 6; i++){
					str = str+BuilderItem.item_id[i]+";";
				}
				for(int i = 0; i < 5; i++){
					str = str+BuilderItem.item_gold[i]+";";
				}
				str = str+BuilderItem.item_gold[5]+"\r\n";
				for(int i = 0; i < 9; i++){
					str = str+Rune.red[i]+";";
				}
				for(int i = 0; i < 9; i++){
					str = str+Rune.blue[i]+";";
				}
				for(int i = 0; i < 9; i++){
					str = str+Rune.yellow[i]+";";
				}
				str = str+Rune.big[0]+";";
				str = str+Rune.big[1]+";";
				str = str+Rune.big[2]+"\r\n";
				for(int j = 0; j < 17; j++){
					str = str+Builder.masteries[0][j]+";";
				}
				for(int j = 0; j < 16; j++){
					str = str+Builder.masteries[1][j]+";";
				}
				for(int j = 0; j < 15; j++){
					str = str+Builder.masteries[2][j]+";";
				}
				str = str+Builder.masteries[2][15]+"\r\n";
				fos.write(str.getBytes());
				Toast.makeText(this, "write success", Toast.LENGTH_SHORT).show();
			}catch(FileNotFoundException e){
				Toast.makeText(this, "에러", Toast.LENGTH_SHORT).show();
			}catch(SecurityException e){
				Toast.makeText(this, "에러", Toast.LENGTH_SHORT).show();
			}catch(Exception e){
				Toast.makeText(this, "에러", Toast.LENGTH_SHORT).show();
			}finally{
				if(fos!=null)
					try {
						fos.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
			}
		}else{
			Toast.makeText(this, "SD Card 인식 실패", Toast.LENGTH_SHORT).show();
		}
	}
}